﻿using System;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using System.Collections;

namespace MongoData
{
    public class MogonDbFactory 
    {
        public  MongoServer Server = null;
        public  MongoDatabase Database = null;
        public MogonDbFactory()
        {
            Int32 port = Convert.ToInt32("27017");
            string hostName = "127.0.0.1";
            var client = new MongoClient(new MongoClientSettings()
            {
                ConnectionMode = ConnectionMode.Automatic,
                ConnectTimeout = TimeSpan.FromMinutes(1),
                Server = new MongoServerAddress(hostName, port),
                MinConnectionPoolSize = 5,
                MaxConnectionPoolSize = 50,
             });
            Server = client.GetServer();
            Server.Connect();
            Database = Server.GetDatabase("test");
        }
        public void Close() {
            if (Server != null)
            {
                Server.Disconnect();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        //public void Close() {
        //    if (Server != null)
        //    {
        //        try
        //        {
        //            Server.Disconnect();
        //        }
        //        catch (Exception e)
        //        {
        //            LogAdapter.Write(e.ToString(),LogAdapter.LogMode.ERROR);
        //        }
        //    }

        //}
    }
}
